/*  1:   */ package org.jetbrains.jps.model.serialization;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.SystemProperties;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.jps.model.JpsGlobal;

import java.io.File;
import java.io.IOException;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */ 
/* 13:   */ public class JpsGlobalElementSaver
/* 14:   */ {
/* 15:33 */   private static final JpsGlobalExtensionSerializer[] a = { new JpsGlobalLoader.PathVariablesSerializer(), new JpsGlobalLoader.GlobalLibrariesSerializer(), new JpsGlobalLoader.SdkTableSerializer() };
/* 16:   */   private final JpsGlobal b;
/* 17:   */   
/* 18:   */   public JpsGlobalElementSaver(JpsGlobal paramJpsGlobal)
/* 19:   */   {
/* 20:39 */     this.b = paramJpsGlobal;
/* 21:   */   }
/* 22:   */   
/* 23:   */   public static void saveGlobalElement(JpsGlobal paramJpsGlobal, String paramString)
/* 24:   */     throws IOException
/* 25:   */   {
/* 26:43 */     File localFile = new File(FileUtil.toCanonicalPath(paramString));
/* 27:44 */     new JpsGlobalElementSaver(paramJpsGlobal).a(localFile);
/* 28:   */   }
/* 29:   */   
/* 30:   */   private void a(File paramFile)
/* 31:   */     throws IOException
/* 32:   */   {
/* 33:48 */     for (JpsGlobalExtensionSerializer localJpsGlobalExtensionSerializer : a) {
/* 34:49 */       a(localJpsGlobalExtensionSerializer, paramFile);
/* 35:   */     }
/* 36:   */   }
/* 37:   */   
/* 38:   */   private void a(JpsGlobalExtensionSerializer paramJpsGlobalExtensionSerializer, File paramFile)
/* 39:   */     throws IOException
/* 40:   */   {
/* 41:54 */     String str = paramJpsGlobalExtensionSerializer.getConfigFileName();
/* 42:55 */     File localFile = new File(paramFile, str != null ? str : "other.xml");
/* 43:56 */     Element localElement = b(localFile);
/* 44:57 */     paramJpsGlobalExtensionSerializer.saveExtension(this.b, JDomSerializationUtil.findOrCreateComponentElement(localElement, paramJpsGlobalExtensionSerializer.getComponentName()));
/* 45:58 */     JDOMUtil.writeDocument(new Document(localElement), localFile, SystemProperties.getLineSeparator());
/* 46:   */   }
/* 47:   */   
/* 48:   */   private static Element b(File paramFile)
/* 49:   */   {
/* 50:62 */     if (!paramFile.exists()) {
/* 51:63 */       return new Element("application");
/* 52:   */     }
/* 53:   */     try
/* 54:   */     {
/* 55:66 */       return JDOMUtil.loadDocument(paramFile).getRootElement();
/* 56:   */     }
/* 57:   */     catch (JDOMException localJDOMException)
/* 58:   */     {
/* 59:69 */       throw new RuntimeException(localJDOMException);
/* 60:   */     }
/* 61:   */     catch (IOException localIOException)
/* 62:   */     {
/* 63:72 */       throw new RuntimeException(localIOException);
/* 64:   */     }
/* 65:   */   }
/* 66:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.serialization.JpsGlobalElementSaver

 * JD-Core Version:    0.7.0.1

 */